package cn.gok.demo21.controller;

import cn.gok.demo21.entity.Clazz;
import cn.gok.demo21.entity.Student;
import cn.gok.demo21.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/clazz")
public class ClazzController {
    @Autowired
    private  ClazzService clazzService;

    //1 查询所有班级信息*
    @RequestMapping("/findAll")
    public List<Clazz> findAllClazz(){
        return clazzService.list(null);
    }
    //2 根据ID查询班级信息*
    @RequestMapping("/findByid")
    public Clazz findClazzByid(@RequestParam Long id){
        return clazzService.getById(id);
    }
    //3 查询所有班级信息和对应的学生信息
    @RequestMapping("/findBycid")
    public List<Clazz> findStudentByCid(){
        return clazzService.findBycid();
    }
    //4 添加班级*
    @RequestMapping("/save")
    public boolean saveClazz(@RequestBody Clazz clazz){
        return clazzService.save(clazz);
    }
    //5 修改班级信息*
    @RequestMapping("/update")
    public Boolean updateClazz(@RequestBody Clazz clazz){
        return clazzService.updateById(clazz);
    }
    //6 根据ID删除班级*
    @RequestMapping("/removeById")
    public boolean removeClazzByid(@RequestParam Long id){
        return clazzService.removeById(id);
    }
    //7 批量删除班级*
    @RequestMapping("/removeByIds")
    public boolean removeClazzByIds(@RequestParam List<Integer> ids){
        return clazzService.removeByIds(ids);
    }
}
